package com.demo.service.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

import com.demo.message.ByteMessage;
import com.demo.service.IMessageService;

@Service
public class MessageService implements IMessageService {

	private static final Logger logger = LoggerFactory.getLogger(MessageService.class);
	@Autowired
	private SimpMessagingTemplate messagingTemplate;

	@Override
	public void subscribeByte(Map<String, Object> headers, byte[] payload) {
		logger.info("消息长度：{}，可以在这里把图片保存下", payload.length);

		// 这里实时把图片推送到/topic/node主题上，发送字节消息
		messagingTemplate.send("/topic/node", new ByteMessage(payload));
	}

}
